package com.kjlink.internal.workreport.report.vo;

import com.kjlink.internal.workreport.base.annotation.NoneColumn;
import com.kjlink.internal.workreport.helper.ReportCommonHelper;
import com.kjlink.internal.workreport.report.model.WorkReport;
import com.kjlink.internal.workreport.user.model.User;

import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.List;

/**
 * 描述:
 * 某个人某天的日报信息
 *
 * @author Vic.xu
 * @since 2024-05-06 9:49
 */
public class DayReportVo implements Serializable {

    private static final long serialVersionUID = 1L;

    private User user;


    private LocalDate day;

    /**
     * 总工时
     */
    private int duration;

    private BigDecimal durationHour;

    private List<WorkReport> reports;

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public List<WorkReport> getReports() {
        return reports;
    }

    public void setReports(List<WorkReport> reports) {
        this.reports = reports;
        if (reports != null && !reports.isEmpty()) {
            this.duration = reports.stream().mapToInt(WorkReport::getDuration).sum();
        }
    }

    public LocalDate getDay() {
        return day;
    }

    public void setDay(LocalDate day) {
        this.day = day;
    }

    public int getDuration() {
        return duration;
    }

    public void setDuration(int duration) {
        this.duration = duration;
    }

    public BigDecimal getDurationHour() {
        if (duration >= 0 && durationHour == null) {
            durationHour = ReportCommonHelper.toHoursNumber(duration);
        }
        return durationHour;
    }

    public void setDurationHour(BigDecimal durationHour) {
        if (durationHour != null) {
            duration = ReportCommonHelper.toMinutesNumber(durationHour).intValue();
        }
        this.durationHour = durationHour;
    }
}
